package cn.tedu.egmvc4.controller;

import cn.tedu._02notice.base.response.JsonResult;
import cn.tedu.egmvc4.mapper.AddressMapper;
import cn.tedu.egmvc4.pojo.dto.AddressInsertParam;
import cn.tedu.egmvc4.pojo.dto.AddressUpdateParam;
import cn.tedu.egmvc4.pojo.entity.Address;
import cn.tedu.egmvc4.pojo.vo.AddressQuery;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/v1/address/")
public class AddressController {
    @Autowired
    private AddressMapper addressMapper;
    //添加收货地址的相关信息
    @PostMapping("add")
    public String add(AddressInsertParam addressInsertParam){

        Address address = new Address();
        BeanUtils.copyProperties(addressInsertParam,address);
        int i = addressMapper.add(address);
        return "新增成功"+i+"条";
    }
    //添加查询功能
    @GetMapping("list")
    public void list(){
        Address address = new Address();
        List<AddressQuery> list = addressMapper.list(address);
        for (AddressQuery addressQuery1 :list){
            System.out.println(addressQuery1);
        }
    }
    //增加修改地址的功能
    @PostMapping("update")
    public String update(AddressUpdateParam addressUpdateParam){
        System.out.println("查看一下"+addressUpdateParam);
        Address address = new Address();
        BeanUtils.copyProperties(addressUpdateParam,address);
        int i  = addressMapper.update(address);
        System.out.println(address);
        return "修改成功";
    }
}
